/**
 * 
 */
package facade.client;

import traer.physics.Particle;
import traer.physics.ParticleSystem;
import traer.physics.Spring;

/**
 * @author cesar
 *
 */
public class JsniFacade {

	public static ParticleSystem CreateParticleSystem (){
		
		return new ParticleSystem();
	}
	
	public static ParticleSystem CreateParticleSystem (float g, float somedrag ){
		
		return new ParticleSystem( g,  somedrag );
	}
	
	public static ParticleSystem CreateParticleSystem ( float gx, float gy, float gz, float somedrag){
		
		return new ParticleSystem(  gx,  gy,  gz,  somedrag);
	}	
	
	public static Particle CreateParticle(float m){
		
		return new Particle( m);
	}	
	
	public static Spring CreateSpring(Particle A, Particle B, float ks, float d, float r ){
		
		return new Spring( A,  B, ks, d, r );
	}		
	
	 
	
	public  native void publish() /*-{
	
	   $wnd.ParticleSystem  = function( gx,  gy,  gz,  somedrag) {
	    	var ParticleSystem = 
	    	@facade.client.JsniFacade::CreateParticleSystem(FFFF)
	    	( gx,  gy,  gz,  somedrag);
	    	
	    	ParticleSystem.makeParticle = function ( mass,  x,  y,  z){ 	    	
	    		var p = ParticleSystem.@traer.physics.ParticleSystem::makeParticle(FFFF)(mass,  x,  y,  z);
				PublishParticle(p);	    	
	    		return p;	    		
	    	}
	    	
			ParticleSystem.makeSpring = ParticleSystem.@traer.physics.ParticleSystem::makeSpring(Ltraer/physics/Particle;Ltraer/physics/Particle;FFF)
			
			ParticleSystem.tick = ParticleSystem.@traer.physics.ParticleSystem::tick();    	
	    	
	    	return ParticleSystem;
	    }	
	    
	   $wnd.Particle  = function(m) {
	    	var Particle = 
	    	@facade.client.JsniFacade::CreateParticle(F)(m);
	    	
			PublishParticle(Particle);
	    	
	    	return Particle;
	    }	
	    
	    
	    function PublishParticle (p)
	    {
	    	p.makeFixed = p.@traer.physics.Particle::makeFixed();
	    	
	    	p.makeFree = p.@traer.physics.Particle::makeFree();
	    	
//	    	p.position = p.@traer.physics.Particle::position();
//	    	PublishVector3D(p.position);
	    	
			p.position = function (){ 
				var vector = p.@traer.physics.Particle::position();
				PublishVector3D (vector);
				return vector;
			}
			
			//return p; 			 	    
	    }	 
	    
   	    function PublishVector3D (p)
	    {
	    	p.x = p.@traer.physics.Vector3D::x();
	   		p.y = p.@traer.physics.Vector3D::y();
	   		p.set = p.@traer.physics.Vector3D::set(FFF);
	   		
	    }	
	    
	    
	
	}-*/;	
	
}
